<template>
    <div class="execution">
        <ecg-chart 
            ref = "ecgChart1"
            :ecgvalue="ecgvalue"
            :headerData="headerData"
        ></ecg-chart>

        <avue-detail :option="detailOption" v-model="form" @submit="handleSubmit">
        </avue-detail>
        <avue-detail :option="checkConditionOption" v-model="checkCondition" @submit="handleSubmit">
        </avue-detail>
        <avue-detail :option="abnormalOption" v-model="abnormal[index]" @submit="handleSubmit" v-for="(item, index) in abnormal" :key="'abnormal' + index">
        </avue-detail>
        <avue-detail :option="ecgfeaturesOption" v-model="ecgfeatures[index]" @submit="handleSubmit" v-for="(item, index) in ecgfeatures" :key="'ecgfeatures' + index">
        </avue-detail>
    </div>
</template>

<script>
    import {fetchDetail, fetchEcgDetail} from '@/api/data/checkreport'
    import {detailOption, abnormalOption, ecgfeaturesOption, checkConditionOption} from '@/const/crud/data/checkreport'
    import EcgChart from '@/components/ecgChart/newIndex'

    export default {
        name: 'iecguserdetail',
        data() {
            return {
                form: {},
                detailOption: detailOption,
                ecgvalue: undefined,
                abnormal: [],
                abnormalOption: abnormalOption,
                ecgfeatures: [],
                ecgfeaturesOption: ecgfeaturesOption,
                checkCondition: [],
                checkConditionOption: checkConditionOption,
            }
        },
        components: {
            EcgChart
        },
        created() {
            this.getData(this.$route.query.id)
            this.getData1(this.$route.query.bizId)
            this.showEcg()
        },
        methods: {
            getData(id) {
                fetchDetail(id).then(res => {
                    console.log(res.data.data)
                    let analyse = JSON.parse(res.data.data.analyse)
                    this.abnormal = analyse.abnormal
                    this.ecgfeatures = analyse.ecgfeatures
                    this.name = res.data.data.iecgCheckCondition.name
                    this.checkCondition = res.data.data.iecgCheckCondition
                })
            },
            getData1(bizId) {
                fetchEcgDetail(bizId).then(res => {
                    console.log(res.data.data)
                    this.ecgvalue = res.data.data.ecgData.split(',')
                    this.form = res.data.data
                    this.form.name = this.name
                })
            },
            handleSubmit() {
                console.log(this.form)
            },
            showEcg() {
                // this.ecgvalue = value.row.ecgData.split(',')

                // let startTime = new Date(value.row.startTime)
                // startTime = startTime.toLocaleDateString().replace(/\//g, "-") + " " + startTime.toTimeString().substr(0, 8)
                this.headerData = {
                    'report_user': `姓名：张三`,
                    'report_sex': '性别：男',
                    'report_age': '年龄：20',
                    'report_hr': 'HR：80 10mm/mV 25mm/s',
                    'report_start_time': `测量时间：`,
                    'report_id': '报告编号：1490951160994'
                }
            }
        }
    }
</script>

<style lang="scss" scoped>
</style>
